<template>
  <div class="app-container">
    <div class="tab-bar">
      <div
        v-for="tab in tabs"
        :key="tab.id"
        class="tab"
        :class="{ active: activeTab === tab.id }"
        @click="activeTab = tab.id"
      >
        {{ tab.label }}
      </div>
    </div>
    <keep-alive :include="['LiveCalendar', 'AnchorInfo', 'LiveEarning']">
      <template v-if="activeTab === 1">
        <!-- 主播信息 -->
        <AnchorInfo />
      </template>

      <template v-else-if="activeTab === 2">
        <!-- 直播流水 -->
        <LiveIncome />
      </template>

      <template v-else>
        <!-- 直播日历 -->
        <LiveCalendar />
      </template>
    </keep-alive>
  </div>
</template>

<script setup lang="ts">
import UserAPI, { UserPageQuery, UserPageVO } from "@/api/system/user";
import AnchorInfo from "./components/AnchorInfo.vue";
import LiveIncome from "./components/LiveIncome.vue";
import LiveCalendar from "./components/LiveCalendar.vue";
import { ref, reactive } from "vue";

//tab切换
interface Tab {
  id: number;
  label: string;
}

const tabs: Tab[] = [
  { id: 1, label: "主播信息" },
  { id: 2, label: "直播流水" },
  // { id: "playlist", label: "陪玩列表" },
  { id: 3, label: "直播日历" },
];

const activeTab = ref(1);

defineOptions({
  name: "User",
  inheritAttrs: false,
});

const queryParams = reactive<UserPageQuery>({
  pageNum: 1,
  pageSize: 10,
});

const pageData = ref<UserPageVO[]>();
const total = ref(0);
const loading = ref(false);

// 查询
function handleQuery() {
  loading.value = true;
  UserAPI.getPage(queryParams)
    .then((data) => {
      pageData.value = data.list;
      total.value = data.total;
    })
    .finally(() => {
      loading.value = false;
    });
}

onMounted(() => {
  handleQuery();
});
</script>

<style lang="scss" scoped>
.app-container {
  // 顶部盒子
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  .tab-bar {
    display: flex;
    margin: 20px 0;
    padding: 17px 0;

    .tab {
      margin-left: 20px;
      padding: 16px 30px 20px;
      box-sizing: border-box;
      min-width: 118px;
      cursor: pointer;
      color: #86909c;
      font-size: 16px;
      background-image: url("@/assets/dashboard/tabBg.png");
      background-size: 110%;
      background-position: center;
    }
    .active {
      color: #3c80ff;
    }
  }
}
</style>
